package hu.village.controller;

import hu.village.pojo.Account;
import hu.village.pojo.Admin;
import hu.village.pojo.Result;
import hu.village.pojo.Village;
import hu.village.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@Slf4j
public class AdminController {

    @Autowired
    private AdminService adminService;

    //管理员登录功能
    @GetMapping("village/admin/login")
    public Result login(String adminName,String password){
        log.info("管理员登录,名:{},密码:{}",adminName,password);
        Admin a = adminService.login(adminName,password);
        if (a == null){
            return Result.error("登录失败");
        }else {
            return Result.success("登录成功");
        }
    }
    //查看财务委员的绑定申请
    @GetMapping("village/admin/selectBinding")
    public Result selectBinding(){
        List<Village> villages = adminService.selectBinding();
        return Result.success(villages);
    }
    //通过或驳回财务委员的绑定
    @GetMapping("village/admin/process")
    public Result process(Integer choice, @RequestBody Village village){
        log.info("处理:{},处理的村庄:{}",choice,village);
        adminService.process(choice,village);
        return Result.success("处理成功");
    }
    //查看待审核的账目
    @GetMapping("village/admin/selectCheckingAccount")
    public Result selectCheckingAccount(){
        List<Account> accountList = adminService.selectCheckingAccount();
        return Result.success(accountList);
    }
    //处理待审核的账目
    @GetMapping("village/admin/processAccount")
    public Result processAccount(Integer choice,@RequestBody Account account){
        log.info("选择:{},要处理的账目:{}",choice,account);
        adminService.processAccount(choice,account);
        return Result.success("处理成功");
    }
    //查看被举报的账目
    @GetMapping("village/admin/selectReportedAccount")
    public Result selectReportAccount(){
        List <Account> accountList = adminService.selectReportAccount();
        return Result.success(accountList);
    }
    //处理被举报的账目
    @GetMapping("village/admin/processReportedAccount")
    public Result processReportAccount(Integer choice ,@RequestBody  Account account){
        log.info("处理被举报的账目,选择:{},账目:{}",choice,account);
        adminService.processReportedAccount(choice,account);
        return Result.success("处理成功");
    }
}
